package C10_4_SeparateQueryFromModifier;

/**
 * 将查询函数和修改函数分离
 **/
public class SeparateQueryFromModifier {

    String foundMiscreant(String[] people) {
        for (int i = 0; i < people.length; i++) {
            if ("Don".equals(people[i])) {
                sendAlert();
                return "Don";
            }
            if ("John".equals(people[i])) {
                sendAlert();
                return "John";
            }
        }
        return "";
    }

    void sendAlert() {
        System.out.println("!!!!!!!!!!!!");
    }

    String foundPerson(String[] people) {
        for (int i = 0; i < people.length; i++) {
            if ("Don".equals(people[i])) {
                return "Don";
            }
            if ("John".equals(people[i])) {
                return "John";
            }
        }
        return "";
    }

    /**
     * 并发问题?
     * @param people
     */
    void foundMiscreantRefactor(String[] people) {
        if (!"".equals(foundPerson(people))) {
            sendAlert();
        }
    }
}
